<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
	<link id="easyuiTheme" rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/icon.css"/>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../resources/js/JsBarcode.all.min.js"></script>
    <script type="text/javascript">
	    var contextPath = function() {
	        return  "/" + location.pathname.split("/")[1];
	    }
	    
		function getValue(name){
			var str=window.location.search;
			if (str.indexOf(name)!=-1){
				var pos_start=str.indexOf(name)+name.length+1;
				var pos_end=str.indexOf("&",pos_start);
				if (pos_end==-1){
					return str.substring(pos_start);
				} else {
					return str.substring(pos_start,pos_end);
				}
			} else {
				return "";
			}
		}
		
		var  themeName = getValue("theme");
		if (themeName!=""){
		    var cssurl  = $('#easyuiTheme').attr('href');  
		    var href = cssurl.substring(0, cssurl.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';  
		    $('#easyuiTheme').attr('href', href);  
		}   
		
	    //将表单数据转为json
	    function form2Json(id) {
	        var arr = $("#" + id).serializeArray();
	        var jsonStr = "";
	        jsonStr += '{';
	        for (var i = 0; i < arr.length; i++) {
	            jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
	        }
	        jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
	        jsonStr += '}';
	        var json = JSON.parse(jsonStr);
	        return json;
	    }
	    
	    //将表单数据转为json格式的字符串，当然也可以JSON.stringify(data)
	    function form2JsonStr(id) {
	        var arr = $("#" + id).serializeArray();
	        var jsonStr = "";
	        jsonStr += '{';
	        for (var i = 0; i < arr.length; i++) {
	            jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
	        }
	        jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
	        jsonStr += '}';
	        return jsonStr;
	    }
	</script>

</head>

<style>
    .datagrid-btable{
        width:100%;
    }
    .datagrid-header-inner{
        width:100%;
    }
    .datagrid-header{
        width:100%;
    }
    .datagrid-htable{
        width:100%;
    }
    .datagrid-cell{margin:auto;}
    .fitem{text-align:center}
    .ftitle{text-align:center}
</style>

<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',title:''">	  
        <table id="datagrid"  class="easyui-datagrid" style="width:100%;height:100%"></table>
        <div id="dgtoolbar">		
        	<form name="searchform" method="post" action="" id ="searchform">
				<td width="70" height="30">
					<strong>&nbsp;投保单号：</strong>
				    <input class="easyui-textbox" type="text" id="search_insureNo" name="insure_no" size=20 >
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;快递单号：</strong>
				    <input class="easyui-textbox" type="text" id="search_deliverNo" name="deliver_no" size=20 >
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;&nbsp;收&nbsp;件&nbsp;人：</strong>
				    <input class="easyui-textbox" type="text" id="search_recipient" name="recipient" size=20 >
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;寄送次数：</strong>
				    <input class="easyui-textbox" type="text" id="search_deliverTimes1" name="deliverTimes1" size=5 >
				    <strong>-</strong>					
				    <input class="easyui-textbox" type="text" id="search_deliverTimes2" name="deliverTimes2" size=5 >
				</td>	
				<br>		
				<td width="70" height="30">
					<strong>&nbsp;电话号码：</strong>
				    <input class="easyui-textbox" type="text" id="search_telephone" name="telephone" size=20 >
				</td>	
				<td width="70" height="30">
					<strong>&nbsp;寄送地址：</strong>
				    <input class="easyui-textbox" type="text" id="search_address" name="address" size=20 >
				</td>	
				<td width="70" height="30">
					<strong>&nbsp;快递信息：</strong>
				    <input class="easyui-textbox" type="text" id="search_deliverInfo" name="deliver_info" size=20 >
				</td>	
				<td width="70" height="30">
					<strong>&nbsp;备注信息：</strong>
				    <input class="easyui-textbox" type="text" id="search_remark" name="remark" size=20 >
				</td>	
				<br>
				<td width="70" height="30">
					<strong>&nbsp;寄送日期：</strong>
					<input id="search_deliverTimeBegin" name="deliverTimeBegin" class="easyui-datebox" editable="false" style="width:100px"></input>					
					<strong>-</strong>
					<input id="search_deliverTimeEnd" name="deliverTimeEnd" class="easyui-datebox" editable="false" style="width:100px"></input>
				</td>
				<td width="70" height="30">
					<strong>&nbsp;返回日期：</strong>
					<input id="search_returnTimeBegin" name="returnTimeBegin" class="easyui-datebox" editable="false" style="width:100px"></input>					
					<strong>-</strong>
					<input id="search_returnTimeEnd" name="returnTimeEnd" class="easyui-datebox" editable="false" style="width:100px"></input>
				</td>	
			</form>
			<a id="submit_search">搜索</a>
			<a id="reset_search">重置</a>
            <a id="btn_add" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" >新增</a>
            <a id="btn_edit" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" >修改</a>
            <a id="btn_delete" href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" >删除</a>
        </div>
    </div>
</div>

<div id="dialog_add_modify" class="easyui-dialog" 
	modal="true" closed="true" 
	style="width:510px;height:420px;padding:10px 20px"
	buttons="#buttons_add_modify">
    <form id="form_add_modify" method="post" >
        <div class="fitem">
            <input id="id_record_id" name="record_id" type="hidden"/>
        	<label>投保单号：</label>
            <input id="id_insure_no" type="text" name="insure_no"  readonly="readonly" class="easyui-textbox" required="true" style="align:left;width:120px"/>        	
            &nbsp;
            <label>快递公司：</label>
            <input type="text" name="deliver_company" class="easyui-textbox" style="width:80px"/>
            &nbsp; 
			<label>第</label>
            <input type="text" name="deliver_times" class="easyui-textbox" required="true"  style="width:20px"/>         
			<label>派</label>
        </div>
        <br>
        <div class="fitem">
            <label>收&nbsp;件&nbsp;人：</label>
            <input type="text" name="recipient" class="easyui-textbox" required="true"  style="width:100px"/>
            &nbsp;&nbsp;&nbsp;&nbsp;       
            <label>联系电话：</label>
            <input type="text" name="telephone" class="easyui-textbox" required="true" style="width:155px"/>
        </div>
        <br>
        <div class="fitem">
            <label>联系地址：</label>
            <input type="text" name="address" class="easyui-textbox" style="width:350px"/>
        </div>
        <br>
        <div class="fitem">
            <label>寄出时间：</label>
			<input name="deliver_time" class="easyui-datebox" editable="false" style="width:100px"></input>	
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>寄出单号：</label>
            <input type="text" name="deliver_no" class="easyui-textbox" style="width:155px"/>
        </div>
        <br>
        <div class="fitem">
            <label>返回时间：</label>
			<input name="return_time" class="easyui-datebox" editable="false" style="width:100px"></input>	
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>返回单号：</label>
            <input type="text" name="return_no" class="easyui-textbox" style="width:155px"/>
        </div>
        <br>
        <div class="fitem">
            <label>配送信息：</label>
            <input type="text" name="deliver_info" class="easyui-textbox" data-options="multiline:true" style="width:350px;height:40px"/>
        </div>
        <br>
        <div class="fitem">
            <label>备注说明：</label>
            <input type="text" name="remark" class="easyui-textbox" data-options="multiline:true" style="width:350px;height:60px"/>
        </div>
    </form>
    <div id="buttons_add_modify">
        <a id="btn_add_modify" href="#" class="easyui-linkbutton">保存</a>
		<a href="#" class="easyui-linkbutton" onclick="javascript:$('#dialog_add_modify').dialog('close')">取消</a>
	</div>
</div>

<div id="dialog-barcode" class="easyui-dialog" title="运单号条形码" data-options="iconCls:'icon-filter'" style="width:350px;height:210px;padding:10px">
	<img id="bcode"/>
</div>

<div id="dialog-policyinfo" class="easyui-dialog" title="" data-options="iconCls:'icon-filter'" style="width:650px;height:460px;padding:1px"></div>

</body>

<script type="text/javascript">

    $(function () {
    	//touch页面,记录用户进入页面
		$.ajax({
			url : contextPath()+"/mdmis/touch",
			type : "get",
			data : {
				//"traceRandom":trace_random,
    			//"recordID":trace_recordID,
    			"target":location.pathname,
    			"operation":"[进入页面]快递信息详情页"
    		},
			dataType : "json",	// 数据返回类型
            cache : false, 	// 是否缓存
            async : true   	// 默认为true 异步请求
		});
    	
    	$('#datagrid').datagrid({
    		loadMsg:'正在加载数据...',
    	    url:contextPath()+'/mdmis/getDeliverInfoListByCondition',
    	    toolbar:'#dgtoolbar',
    	    queryParams: form2Json("searchform"),
    	    pagination: true,
            pageSize:'1000',
            pageList:[1000,2000,5000],            
            rownumbers: true,
            striped: true,
            fit: true,
            fitColumns: false, //不自动适应列宽
            singleSelect: false, 
            selectOnCheck: true,
            checkOnSelect: true,
            loader: function(param, success, error) {
            	$.ajax({
            		type : $(this).datagrid("options").method,
            		url : $(this).datagrid("options").url,
            		dataType : 'json',
            		contentType : 'application/json;charset=utf-8', // 设置请求头信息
            		data : JSON.stringify(param),
            		success : function(result) {
            			success(result);
            		}
            	});
            },
    	    columns:[[
    			{field:'ck',checkbox:true}, 
    			{field:'insure_no',title:'投保单号',width:130,
    				formatter: function(value,row,index){
    			        if (value) {
    			        	return "<a href='javascript:void(0)' onclick=showPolicyInfo('"+value+"')>"+value+"</a>";
    			        } else {
    			            return "";
    			        }
    				}	
    			},
    			{field:'deliver_times',title:'派',width:20},
    			{field:'recipient',title:'收件人',width:50},
    			{field:'telephone',title:'联系电话',width:100},
    			{field:'deliver_no',title:'寄出单号',width:130,
    				formatter: function(value,row,index){
    			        if (value) {
    			        	return "<a href='javascript:void(0)' onclick=showBarcode('"+value+"')>"+value+"</a>";
    			        } else {
    			            return "";
    			        }
    				}	
    			},
    			{field:'deliver_time',title:'寄出时间',align:'center',width:80},
    			{field:'return_no',title:'返回单号',width:130,
    				formatter: function(value,row,index){
    			        if (value) {
    			        	return "<a href='javascript:void(0)' onclick=showBarcode('"+value+"')>"+value+"</a>";
    			        } else {
    			            return "";
    			        }
    				}	
    			},
    			{field:'return_time',title:'返回时间',align:'center',width:80},
    			{field:'address',title:'地址',width:300},
    			{field:'deliver_company',title:'快递',width:40},
    			{field:'deliver_info',title:'快递信息',width:80},
    			{field:'remark',title:'备注',width:100}
    	    ]]
    	});      	
    	  
		//点击搜索
		$("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true }).click(function () {
			var params = form2Json("searchform");			
			params['returnNo'] = $('#search_deliverNo').textbox('getValue');
            $('#datagrid').datagrid({ queryParams: params });   
        });
		//点击重置
		$("#reset_search").linkbutton({ iconCls: 'icon-reload', plain: true }).click(function () {
            $('#search_insureNo').textbox('setValue','');
            $('#search_deliverNo').textbox('setValue','');
            $('#search_deliverTimes1').textbox('setValue','');
            $('#search_deliverTimes2').textbox('setValue',''); 
            $('#search_recipient').textbox('setValue','');
            $('#search_telephone').textbox('setValue','');
            $('#search_address').textbox('setValue',''); 
            $('#search_deliverTimeBegin').textbox('setValue',''); 
            $('#search_deliverTimeEnd').textbox('setValue',''); 
            $('#search_returnTimeBegin').textbox('setValue',''); 
            $('#search_returnTimeEnd').textbox('setValue',''); 
            $('#search_deliverInfo').textbox('setValue',''); 
            $('#search_remark').textbox('setValue',''); 
            //$('#datagrid').datagrid('reload');  
            $('#datagrid').datagrid({ queryParams: form2Json("searchform") });   
        });
		//点击新增
		$("#btn_add").linkbutton({ iconCls: 'icon-add', plain: true }).click(function () {
			//清空表单
			//form('clear')会将所有框都清空，包括combobox。
			//$('#form_add_modify').form('clear')
			//form('reset')则只会清空日期框，不会清空combobox。
			$('#form_add_modify').form('reset');
	        $('#dialog_add_modify').dialog('open').dialog('setTitle','新增信息');
			//将投保单输入栏的编辑状态修改为可编辑
            $('#id_insure_no').textbox('readonly',false);
			//将窗口中的保存按钮修改为新增操作
			$("#btn_add_modify").unbind("click");
			//必须先解除绑定，再重新绑定，否则可能会出现重复响应。						
			$("#btn_add_modify").bind("click", function() {
				$.messager.confirm('Confirm','确定要添加新信息?',function(r){
				    if (r){
				    	$.ajax({
							type:'POST',
							url:contextPath()+'/mdmis/...........',
						    data:form2JsonStr('form_add_modify'),
						    dataType:'json',
							contentType: 'application/json',
						    beforeSend: function () {
								$.messager.progress({
									title: '提示', 
									msg: '操作进行中，请稍候……', 
									text: '' 
								});
						    },
						    complete: function () {
								$.messager.progress('close');
						    },
						    success:function(result){				
								if (result.success){
					                $('#datagrid').datagrid('reload');	// reload data
			                        $('#dialog_add_modify').dialog('close');
					                $.messager.show({
					                    title: 'Success',
					                    msg: '操作完成！'
					                });
					            } else {
					                $.messager.show({	// show error message
					                    title: 'Error',
					                    msg: result.errMsg
					                });
					            }
							}
						});
					}
				});						      
	        });
        });
		//点击编辑
		$("#btn_edit").linkbutton({ iconCls: 'icon-edit', plain: true }).click(function () {
		      var rows = $('#datagrid').datagrid('getSelections');
		      if (rows){
		    	  if (rows.length==0) {
						$.messager.show({
						    title: '操作错误',
						    msg: '您未勾选任何数据，请选择需要编辑的数据！'
						});
		    	  } else if (rows.length>1){
						$.messager.show({
						    title: '操作错误',
						    msg: '您已经勾选了'+rows.length+'条数据，请勿选择多条数据进行同时编辑！'
						});		    		  
		    	  } else {
		    		  	//取出信息
		    		  	var info = rows[0];
						//显示未修改前的信息
						$('#form_add_modify').form('load',info);
				        $('#dialog_add_modify').dialog('open').dialog('setTitle','修改信息');
						//将投保单输入栏的编辑状态修改为不能编辑
           	 			$('#id_insure_no').textbox('readonly',true);
						//将窗口中的保存按钮修改为保存操作
						$("#btn_add_modify").unbind("click");
						//必须先解除绑定，再重新绑定，否则可能会出现重复响应。						
						$("#btn_add_modify").bind("click", function() {
							$.messager.confirm('Confirm','确定要更新该保单信息?',function(r){
							    if (r){
							    	$.ajax({
										type:'POST',
										url:contextPath()+'/mdmis/modifyDeliverInfo',
									    data:form2JsonStr('form_add_modify'),
									    dataType:'json',
										contentType: 'application/json',
									    beforeSend: function () {
											$.messager.progress({
												title: '提示', 
												msg: '操作进行中，请稍候……', 
												text: '' 
											});
									    },
									    complete: function () {
											$.messager.progress('close');
									    },
									    success:function(result){				
											if (result.success){
								                $('#datagrid').datagrid('reload');	// reload data
						                        $('#dialog_add_modify').dialog('close');
								                $.messager.show({
								                    title: 'Success',
								                    msg: '操作完成！'
								                });
								            } else {
								                $.messager.show({	// show error message
								                    title: 'Error',
								                    msg: result.errMsg
								                });
								            }
										}
									});
								}
							});						      
				        });
		    	  }		    	  
		      }
		});
		$("#btn_delete").linkbutton({ iconCls: 'icon-remove', plain: true }).click(function () {
		      var rows = $('#datagrid').datagrid('getSelections');
		      if (rows){
		          $.messager.confirm('Confirm','确定要删除所选择的数据?',function(r){
		              if (r){
		            	  var ids="";
		            	  for (var i in rows){
		            		  ids += rows[i].record_id+",";
		            	  }
		                  $.post(contextPath()+'/mdmis/removeDeliverInfo',{ids:ids},function(result){
		                      if (result.success){
		                          $('#datagrid').datagrid('reload');	// reload data
		                          $.messager.show({
		                              title: 'Success',
		                              msg: '操作完成！'
		                          });
		                      } else {
		                          $.messager.show({	// show error message
		                              title: 'Error',
		                              msg: result.errMsg
		                          });
		                      }
		                  },'json');
		              }
		          });
		      }
        });
		//初始化页面时，不显示条形码的提示框
    	$('#dialog-barcode').dialog('close');
		//初始化页面时，不显示保单详细信息页
    	$('#dialog-policyinfo').dialog('close');
    })
    //显示条形码
    function showBarcode(s){
    	$("#bcode").JsBarcode(s);
    	$('#dialog-barcode').dialog('open');
    }
    //显示保单详细信息
    function showPolicyInfo(insure_no){
    	$("#dialog-policyinfo").dialog({
			title:insure_no,
    		//modal:true,
    		content:"<iframe scrolling='auto' frameborder='0' src='"+contextPath()+"/mdmis/policy_information.html?insure_no="+insure_no+"' style='width:100%; height:100%; display:block;'></iframe>"    		
    	});
    	$('#dialog-policyinfo').dialog('open');
    }

</script>


</html>



